//
//  BZMainTabBar.swift
//  weibo
//
//  Created by zzx on 2017/7/22.
//  Copyright © 2017年 zzx. All rights reserved.
//

import UIKit

class BZMainTabBar: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        
        let bzTabBar = BZTabBar()
        
        bzTabBar.bzTabBarDelegate = self
        
        bzTabBar.composeButtonClouse = { [unowned self] in
            
            print("这是闭包")
            
            print(self)
            
        }
        
        self.setValue(bzTabBar, forKey: "tabBar")
        
        addChildViewController(childController: BZHomeTableVC(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(childController: BZMessageTabelVC(), title: "搜索", imageName: "tabbar_message_center")
        
        addChildViewController(childController: BZDisoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(childController: BZMineTableViewController(), title: "我的", imageName: "tabbar_profile")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    //MARK:- 封装child的Controller
    func addChildViewController(childController: UIViewController, title: String ,imageName: String) {
        
        childController.title = title
        
        childController.tabBarItem.image = UIImage(named: imageName)
        
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1)], for: .selected)
        
        //创建nav
        let nav = BZNavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
        
    }

}

extension BZMainTabBar: BZTabBarDelegate{

    func clickComposeBottonOperation() {
        
        print("这是回调")
        
    }

}
